package com.tengju.bff.interfaces.app.user.facade;

import com.tengju.bff.interfaces.app.user.assembler.ManageCentreDealerNewAssembler;
import com.tengju.bff.interfaces.app.user.vo.ReportDealerDominationNewUserVO;
import com.tengju.bff.interfaces.app.user.vo.ReportDealerNewUserVO;
import com.tengju.data.domain.model.user.ReportDealerDominationNewUserInfo;
import com.tengju.data.domain.model.user.ReportDealerDominationNewUserRepository;
import com.tengju.data.domain.model.user.ReportDealerNewUserInfo;
import com.tengju.data.domain.model.user.ReportDealerNewUserRepository;
import com.tengju.user.domain.model.user.UserIdCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class ManageCentreDealerNewFacade {

    /**
     * 社群标题配置
     */
    @Value("#{${app.manage.centre.show.association.title.map}}")
    private Map<Integer,String> associationTitleMap;

    /**
     * 区域市场标题配置
     */
    @Value("#{${app.manage.centre.show.domination.title.map}}")
    private Map<Integer,String> dominationTitleMap;

    /**
     * 社群排序配置
     */
    @Value("#{${app.manage.centre.show.association.order.map}}")
    private Map<Integer,Integer> associationOrderMap;

    /**
     * 区域市场排序配置
     */
    @Value("#{${app.manage.centre.show.domination.order.map}}")
    private Map<Integer,Integer> dominationOrderMap;



    private final ReportDealerNewUserRepository reportDealerNewUserRepository;

    private final ReportDealerDominationNewUserRepository reportDealerDominationNewUserRepository;

    public List<ReportDealerNewUserVO> getDealerNewUser(UserIdCode userIdCode,Integer month) {
        if (userIdCode == null) {
            return Collections.emptyList();
        }
        List<ReportDealerNewUserInfo> infoList =
                reportDealerNewUserRepository.selectByIdCodeAndMonth(userIdCode,month);

        return ManageCentreDealerNewAssembler.toNewUserVOList(infoList,
                month,
                associationTitleMap,
                associationOrderMap);
    }



    public List<ReportDealerDominationNewUserVO> getDealerDominationNewUser(UserIdCode userIdCode,Integer year) {
        if (userIdCode == null) {
            return Collections.emptyList();
        }
        List<ReportDealerDominationNewUserInfo> infoList =
                reportDealerDominationNewUserRepository.selectByIdCodeAndYear(userIdCode,year);

        return ManageCentreDealerNewAssembler.toDominationNewUserVOList(infoList,
                year,
                dominationTitleMap,
                dominationOrderMap);
    }

}
